/**
 * Created by Administrator on 2018/2/23.
 * by gm
 * CountDown 倒计时 插件
 */
;$(function ($, window, document, undefined) {

    SecondCountDown = function (container, options) {

        "use strict"; //stirct mode not support by IE9-

        if (!container) return;

        var options = options || {},
            clock,
            isrun    = 0,
            waitTime = options.waitTime?options.waitTime:60,// 倒计时秒数
            runText  = options.runText?options.runText:'重新获取',// 运行提示
            initText = options.initText?options.initText:'获取验证码';  // 初始化提示

        function init() {
            if(isrun){
                return false;
            }
            container.attr({disabled:true});
            clock = setInterval(function(){
                countDownRun(container);
            }, 1000);
        }

        function countDownRun (container) {
            isrun = 1;
            waitTime--;
            container.val(runText+"(" + waitTime + ")");
            if(waitTime==0){
                clearInterval(clock);
                container.attr({disabled:false}).val(initText);
                waitTime = options.waitTime;
                isrun = 0;
            }
        }
        init();
    };
}(jQuery, window, document));